﻿using Inovout.Organizations.Memberships.Models;
using Inovout.Organizations.Models;
using Inovout.Repositories;
using NHibernate.Criterion;

namespace Inovout.Organizations.Memberships.Repositories
{
    public class OrganizationMembershipRepository : DataObjectRepository<OrganizationMembership>
    {

        public OrganizationMembership FindByUserName(string userName)
        {
            var list = base.OpenSession().CreateCriteria<OrganizationMembership>()
                .CreateCriteria("User", "user")
                .Add(Restrictions.Eq("user.Name", userName).IgnoreCase())
                .List<OrganizationMembership>();
            return Single(list);
        }

        public OrganizationMembership FindByOrganizationUnit(OrganizationUnit organizationUnit)
        {
            return base.Find(Restrictions.Eq("Organization.Id", (object)organizationUnit.Id));
        }
    }
}
